/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.swirrel.listener;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelKeyListener extends AbstractSwirrelListener implements KeyListener{
    private final MethodCall keyTypedCall;
    private final MethodCall keyPressedCall;
    private final MethodCall keyReleasedCall;

    public SwirrelKeyListener(
            MethodCall keyTypedCall,
            MethodCall keyPressedCall,
            MethodCall keyReleasedCall) {
        this.keyTypedCall = keyTypedCall;
        this.keyPressedCall = keyPressedCall;
        this.keyReleasedCall = keyReleasedCall;
        if (!checkSignature(keyTypedCall, KeyEvent.class) ||
            !checkSignature(keyPressedCall, KeyEvent.class) ||
            !checkSignature(keyReleasedCall, KeyEvent.class)) {
            throw new SwirrelException("Method must have none or one KeyEvent argument");
        }
    }

    public void keyTyped(KeyEvent e) {
        call(keyTypedCall, e);
    }

    public void keyPressed(KeyEvent e) {
        call(keyPressedCall, e);
    }

    public void keyReleased(KeyEvent e) {
        call(keyReleasedCall, e);
    }
}
